package dao;

import java.util.List;

/**
 * Defines a common interface for all data access operation for a given type
 * <code>T</code>.
 * 
 * @author Sebastian Gabmeyer
 * 
 * @param <T>
 *            the type of the entity.
 */
public interface DAO<T> {
	/**
	 * Load a single entity of type T with the given ID value.
	 * 
	 * @param id
	 *            the ID of the entity to load from the database.
	 * @return the retrieved entity -OR- <tt>null</tt> if not found.
	 */
	T load(long id);

	/**
	 * Load all entities of the given type T from the database.
	 * 
	 * @return a list of entities of type T.
	 */
	List<T> loadAll();

	/**
	 * Persist the given entity of type <code>T</code> to the database. If the
	 * entity is already present in the database, it is updated instead.
	 * 
	 * @param entity
	 *            the entity to persist.
	 */
	void persist(T entity);

	/**
	 * Update the given entity of type <code>T</code> in the database. If the
	 * entity is not present in the database, it will be inserted.
	 * 
	 * @param entity
	 *            the entity to update.
	 */
	void update(T entity);

	/**
	 * Delete an entity specified by the given <code>id</code> value from the
	 * database.
	 * 
	 * @param id
	 *            the <code>id</code> value of the entity to be deleted.
	 */
	void delete(long id);
}
